package com.hzw.saas.service.old.storage.util;

import java.util.List;
import java.util.Objects;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.hzw.saas.api.old.storage.constants.StorageConstants;
import com.hzw.saas.common.config.util.AssertUtil;
import cn.hutool.core.collection.CollectionUtil;

/**
 * @author zzl
 * @since 02/25/2021
 */
public class StorageUtil {

    /**
     * 判断是否为根目录ID
     *
     * @param folderId 目录ID
     * @param throwEx  当为rootId时是否抛出异常
     * @return true or false
     */
    public static boolean isRootFolder(String folderId, boolean throwEx) {
        boolean flag = Objects.equals(StorageConstants.ROOT_FOLDER_ID, folderId);
        AssertUtil.assertThrow("目录ID异常", flag && throwEx);
        return flag;
    }

    /**
     * 获取路径对应的目录名列表
     *
     * @param path 路径字符串
     * @return 路径名称列表
     */
    public static List<String> resolvePath(String path) {
        String[] nameArray = path.split("[\\\\/]");
        List<String> pathList = CollectionUtil.list(false, nameArray);
        pathList.removeIf(StringUtils::isBlank);
        return pathList;
    }

}
